import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sp_util/sp_util.dart';
import 'package:yp/config/config.dart';
import 'package:yp/services/api.dart';

import '../../../helper.dart';
import 'state.dart';
import 'package:yp/pages/address_selector/address_model.dart';

class NearbyBusinessHallLogic extends GetxController {
  final state = NearbyBusinessHallState();

  @override
  void onInit() {
    super.onInit();
    state.locationResult = Get.arguments;
    state.contentTextController = TextEditingController();
    state.contentFocusNode = FocusNode();

    state.searchBool = false;
    selfHelpAddress();
  }

  //获取自提点列表数据 附近营业厅
  void selfHelpAddress() {
    getCurrentLocationInfo(success: (data) {
      var orderAddress = data['addressInfo'];

      var params = {
        'sub_unit_name': state.contentTextController.text ?? '',

        "prv_num_id": orderAddress['prv_num_id'],
        "city_num_id": orderAddress['city_num_id'],
        "city_area_num_id": orderAddress['city_area_num_id'],
        "town_num_id": orderAddress['town_num_id'],
        "maplocation_x": orderAddress['maplocation_x'],
        "maplocation_y": orderAddress['maplocation_y'],
        "adr_num_id": orderAddress["adr_num_id"],

        'ec_shop_num_id': SpUtil.getInt('storeShopNum'),
        "page": 1,
        "page_size": 30,
        "is_pick_up": null,
        'user_type': null, //用户类型:1网格员,2KOC
        'usr_num_id': SpUtil.getInt('empeNumId')
      };
      // print("locaton-$params");

      // toast("city_num_id:${params['city_num_id']}");
      Api.selfHelpAddress(params).listen((event) {
        state.selfHelpAddressList = event["sub_unit_shop_list"] ?? [];
        update();
      });
    });
  }

  void onSearchClick(bool searchBool) {
    state.searchBool = searchBool;
    selfHelpAddress();
  }
}
